package com.gtamos.dicebot.printers;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;

import com.gtamos.dicebot.constants.DiceBotConstants;
import com.gtamos.dicebot.gambling.game.AbstractGambling;

import dice.client.web.DiceWebAPI;

public class ConsolePrinter {

	public static void printInitialization(AbstractGambling abstractGambling){
		Integer totalBets = DiceBotConstants.BETS_CYCLES*DiceBotConstants.MAX_BETS;
		System.out.println("------------------------------------------------------");
		System.out.println("STARTING " + totalBets + " BETS BOT IN "  +DiceBotConstants.BETS_CYCLES + " CYCLES (Estimated time: " + (int) (totalBets*DiceBotConstants.ONE_BET_IN/60/60) + " hours )" );
		System.out.println("------------------------------------------------------");
	}
	
	public static void printOnCycleStartInfo(Integer cycleNumber, BigDecimal initialBalance){
		System.out.println("START CYCLE# " + (cycleNumber + 1));
		System.out.println("------------------------------------------------------");
		System.out.println("Initial balance: " + initialBalance);
	}
	
	public static void printPlacedBetStatus(Boolean success){
		if(!success){
			System.out.print ("[NOT SUCESS] ");
		}else{
			System.out.print ("[SUCESS] ");
		}
	}
	
	public static void printBalanceInfo(Boolean losseGambling, BigDecimal initialBetBalance, BigDecimal newBalance, BigDecimal secret){
		String gamblingResult = "WIN";
		if(losseGambling){
			gamblingResult = "LOSS";
		}
		System.out.print( " New balance: " + newBalance + " ("+ gamblingResult +")(" + secret + ")");
		System.out.println(" (" + newBalance.subtract(initialBetBalance).toPlainString() + ")");
	}
	
	public static void printBetInfo(Date d1, Date d2, String betType, Integer betNumber, BigDecimal payIn){
		System.out.print(betType + (betNumber + 1) + ": Delayed " + (d2.getTime() - d1.getTime()) /1000  + " SEC, Bet " + payIn.toPlainString() + "," );
	}
	
	public static void printCycleResume(Integer betsNumber, Date d0, BigDecimal initialBalance, BigDecimal newBalance, BigDecimal maxBet, Integer win, Integer maxConsecutiveWins, Integer loss, Integer maxConsecutiveLoss){
		System.out.println("");
		System.out.println("");

		System.out.println("--------------------------------------------------RESUME-----------------------------------------------------");
		System.out.println("");
		System.out.println("BETS: " + betsNumber); 
		System.out.println("TOTAL TIME: " + (new Date().getTime() - d0.getTime()) / 1000 + " SEC");
		System.out.println("I.BALANCE: " + initialBalance);
		System.out.println("F.BALANCE: " + newBalance.toPlainString());
		System.out.println("MAX BET: " + maxBet.toPlainString());
		System.out.println("WINS: " + win);
		System.out.println("MAX CONSECUTIVE WINS: " + maxConsecutiveWins);
		System.out.println("LOSSES: " + loss);
		System.out.println("MAX CONSECUTIVE LOSSES: " + maxConsecutiveLoss);
		System.out.println("PROFIT: " + newBalance.subtract(initialBalance).toPlainString() + " (" + DiceWebAPI.TruncateSatoshis(newBalance.subtract(initialBalance).multiply(new BigDecimal(100)).divide(initialBalance,RoundingMode.UP)).toPlainString() + "%)");
		System.out.println("");
		System.out.println("-------------------------------------------------------------------------------------------------------------");
		System.out.println("");
	}

}
